********************************************************************
*****
*****  C:\work\PLModel1\newsimul\Hebb2_fits.txt
*****  22-23 June 2005 -- Fit new version PLM_HEBB2.M
*****  to feedback and no-feedback data simultaneously.
*****  Compare with PLExp2/modelfits/Hebb_fits.txt
*****
********************************************************************

 clear all ; cd('C:\work\PLModel1')
 load sched; load PLM_CACHE; load HUMAN_ZCONGR; l={'1.0 c/d','1.4 c/d','2.0 c/d','2.8 c/d','4.0 c/d'};
 edit PLM_params;edit PLM_Hebb2;

descr=zeros(9600,5,10);for k=1:10 d=block_from_cache(sched1,PLM_CACHE);descr(:,:,k)=cat(1,d{:});end;
for k=6:10 d=block_from_cache(sched2,PLM_CACHE);descr(:,:,k)=cat(1,d{:});end;clear d

 stim=descr(:,:,1);Mparams=PLM_params;Mparams.out_noise=.158;Mparams.criterion=.87;Mparams.fdbk_fract=0;

Mparams.out_gain=4;[o,Wh]=PLM_Hebb2(stim,Mparams);Rra=Wh(36,:);aLra=Wh(37,:);plot(Rra,'.')
plot(o(:,2),o(:,6),'.');axis([-.5 .5 -.5 .5]);axis square;grid on;xlabel('early act');ylabel('late act');title(['fdbk weight = ' num2str(Mparams.fdbk_wgt)]);refline(1,0);

figure(1);foo=Wh(:,1:10:end);for k=1:5 subplot(2,3,k);plot(foo([1:7]+7*k-7,:)','b');axis([0 1090 -.5 +.5]);set(gca,'xtick',[0:120:1080],'xticklabel',[],'ytick',[-.5:.1:+.5]);grid on;end
subplot(2,3,6);plot(foo(36,:)','k');axis([0 1090 -1 +1]);set(gca,'xtick',[0:120:1080],'xticklabel',[],'ytick',[-1:.2:+1]);grid on

 figure(2);hist(o(:,2),[-.5:.01:.5]);axis([-.55 .55 0 Inf]);describe(o(:,2))


%%% After some preliminary fooling around, the following parameters seem
%%% a promising starting point for the no-feedback condition.  6/23/2005
Mparams = 
      rep_size: [7 5 1]
       max_act: 0.5000
      rep_gain: 0.8000
      out_gain: 6
     rep_noise: 0.1000
     out_noise: 0.1580
      W_minmax: [-1 1]
        W_init: 0.1700
       W0_seed: [35x1 double]
    learn_rate: 0.0020
    runav_rate: 0.0200
     criterion: 0.8700
      fdbk_wgt: 0.5000
    fdbk_fract: 0
      blk_size: 300

 actL=o(:,2);describe(actL);   % the histogram is a smooth bi-modal distribution
    Mean  Std.dev       Min     Q25  Median     Q75     Max
------------------------------------------------------------
  -0.005    0.284     -0.50   -0.27   -0.01    0.25    0.50

% For comparison with PLM_Hebb1, when out_gain=40 (and learn_rate=.0015=default), 
% the distribution of the decision-unit activation is concentrated at the extremes:

    Mean  Std.dev       Min     Q25  Median     Q75     Max
------------------------------------------------------------
  -0.007    0.464     -0.50   -0.50   -0.04    0.50    0.50

%%% Incidentally, the latter parameter set replicates our original no-feedback
%%% fits with the original version (PLM_Hebb1).
%%% Mparams = 
%%%       out_gain: 40
%%%      out_noise: 0.1580
%%%     learn_rate: 0.0015
%%%      criterion: 0.8700
%%%       fdbk_wgt: xxxx    %irrelevant without feedback



###########################################################################
###########################################################################
######
######  P L A N    O F    A T T A C K             (as of 23 June 2005)
######
######  1. Fit PLM_Hebb2 to the no-feedback data using the old-version
######     parameters as a starting point.  Five free parameters:
######     out_gain, out_noise, W_init, learn_rate, criterion
######  2. Fit PLM_Hebb2  *without* feedbackto the PLExp1 data using
######     the parameters determined in 1. as a starting point.
######  3. Inspect the resulting fits and the optimal parameters. See if it
######     is possible to re-use some values from PLPaper1. Iterate 1.&2.
######  4. Fit PLM_Hebb2 to first to PLExp1 data and then to PLExp2 data.
######     Use the no-feedback params from 2. and 3 as a starting pt.
######     Additional param: fdbk_wgt
######  5. Inspect the resulting fits and the optimal parameters. See which
######     parameters can be shared b/n the fdbk and no-feedback conditions.
######  6. Fit a reduced parameter set to the feedback and/or no-fdbk data.
######  7. Do simulations on the effect of feedback, all else being equal.
######  8. Prepare final fits and publication-grade figures.
######
###########################################################################
###########################################################################



***************************************************************************
****
****  23 June 2005  --  Preliminary no-feedback fits
****

 clear all ; cd('C:\work\PLModel1'); load PLM_CACHE;
 load('C:\work\PLExp2\modelfits\sched36.mat');load('C:\work\PLPaper2\simul\all_zP_data.mat');clear Idef mdprfk32 mdprnf36 mZfk32 mZnf36;whos

  Name            Size         Bytes  Class
------------------------------------------------------------
  PLM_CACHE      12x1       16803792  struct array (global)
  bnd36           1x6             48  double array
  eZfk32         32x6           1536  double array
  eZnf36         36x6           1728  double array
  edprfk32       32x3            768  double array
  edprnf36       36x3            864  double array
  sched36_1      36x1          10224  cell array
  sched36_2      36x1          10224  cell array
------------------------------------------------------------

 global HUMAN_ZCONGR ; HUMAN_ZCONGR = eZnf36';


%% Prepare and pack stimuli and "chance events",  see MAKE_CHEV
N_trials=10800; N_runs=2*10;
for k=1:N_runs/2 d=block_from_cache(sched36_1,PLM_CACHE);Mdata(k).stim=cat(1,d{:});Mdata(k).chev=make_chev(N_trials);end;
for k=(N_runs/2+1):N_runs d=block_from_cache(sched36_2,PLM_CACHE);Mdata(k).stim=cat(1,d{:});Mdata(k).chev=make_chev(N_trials);end;
d=cat(3,Mdata(:).stim);d=squeeze(d(:,3,:));imagesc(d);clear d  % sanity check


%%  Use PLM_Hebb1 no-feedback params as initial approximation for the new parameter search.
 Mparams=PLM_params;Mparams.fdbk_fract=0;Mparams.out_noise=.1578;Mparams.criterion=.8679;Mparams.out_gain=6
Mparams = 
      rep_size: [7 5 1]
       max_act: 0.5000
      rep_gain: 0.8000
      out_gain: 6
     rep_noise: 0.1000
     out_noise: 0.1578
      W_minmax: [-1 1]
        W_init: 0.1700
       W0_seed: [35x1 double]
    learn_rate: 0.0015
    runav_rate: 0.0200
     criterion: 0.8679
      fdbk_wgt: 0.5000      % irrelevant
    fdbk_fract: 0           % <-- Important!
      blk_size: 300

%%  Test-run to make sure the program runs
%
 md=Mdata(1);md.params=Mparams
md =  stim: [10800x5 double]
      chev: [10800x2 double]
    params: [1x1 struct]

 [o,Wh]=PLM_Hebb2(md);foo=Wh(:,1:10:end);for k=1:5 subplot(2,3,k);plot(foo([1:7]+7*k-7,:)','b');axis([0 1090 -.5 +.5]);set(gca,'xtick',[0:120:1080],'xticklabel',[],'ytick',[-.5:.1:+.5]);grid on;end
 Z=PLM_Zcongr2(md);clf;plot_PLM_fit(Z,eZnf36');   % [6x36]
 PLM_sumsqfit2(Z)
ans = 8.0267        % for comparison, the mimimal sumsq for PLM_Hebb1 are: PLM_sumsqfit2(mZnf36',eZnf36') = 7.5112

 ssq=zeros(N_runs,1);for k=1:N_runs md=Mdata(k);md.params=Mparams;Z=PLM_Zcongr2(md);ssq(k)=PLM_sumsqfit2(Z);end;describe(ssq)
    Mean  Std.dev       Min     Q25  Median     Q75     Max      % takes about 1 min on Dell OptiPlex
------------------------------------------------------------
   9.078    0.732      7.52    8.84    9.01    9.24   10.47

 reshape(ssq,5,4),clear ssq
   --  Schedule A --   --  Schedule B --
    8.0267    8.0999    9.2494    9.1068
    8.8993    9.1462   10.4698    9.0956
    9.2317    8.9513    8.7940   10.2357
    8.9312   10.1584    7.5191    8.8934
    8.7215    8.9539    9.0721   10.0074


%%%% Search parameters  (PLM_TEMPLATE.M was modified for that purpose)
%
 Sparams=PLM_search_params;Sparams.params=Mparams,clear Mparams
Sparams = 
    lsfun_name: 'PLM_paramsearch'
    sumsq_name: 'PLM_sumsqfit2'
    model_name: 'PLM_Zcongr2'
        params: [1x1 struct]
     p2v_templ: {1x5 cell}
     v2p_templ: {1x5 cell}
        bounds: [2x5 double]
         optns: [1x1 struct]

 Sparams.p2v_templ'
ans = 
    'VAL = PARAMS.learn_rate *100 ;'
    'VAL = PARAMS.out_noise ;'
    'VAL = PARAMS.W_init ;'
    'VAL = PARAMS.out_gain /10 ;'
    'VAL = PARAMS.criterion ;'

 Sparams.bounds
ans =
    0.1000    0.1000    0.1000    0.1000    0.5000
    1.0000    0.3000    0.3000    2.0000    3.0000

 x0=params2vector(Sparams.params,Sparams.p2v_templ)
x0 =0.1500    0.1578    0.1700    0.6000    0.8679

% Test-run on 1 stimulus set
 tic;md=Sparams;md.model_data=Mdata(1);ssq=PLM_paramsearch(x0,md);toc;ssq
ssq = 8.0267    % same as above     % elapsed_time = 4.6 sec

% Test-run on 20 stimulus sets
 tic;md=Sparams;md.model_data=Mdata;ssq=PLM_paramsearch(x0,md);toc;ssq, clear ssq md
ssq = 9.0782    % same as above     % elapsed_time = 59 sec


%%%%%  Now try the search itself  23 June 2005
%
 tic;[Sres.opt_par,Sres.ssq,Sres.opt_X,Sres.det]=paramsearch(Mdata,Sparams);toc
% elapsed_time = 100 minutes on the Dell OptiPlex

 Sres_nofk36=Sres, save('C:\work\PLModel1\newsimul\Sres.mat','Sres_nofk36');clear Sres;
Sres_nofk36 = 
    opt_par: [1x1 struct]
        ssq: 8.7840
      opt_X: [0.1682 0.1534 0.1608 0.5184 0.9094]
        det: [1x1 struct]

%% The summed squared error is SSQ=8.7840=9*0.976 for the no-feedback condition under PLM_Hebb2.
%% For comparison, SSQ was 8.9745=9*0.997 for the old PLM_Hebb1 model in the no-feedback condition.
%% The old model had SSQ=7.7384=8*0.9673 in the feedback condition. See C:\work\PLModel1\simul\paramsearch.Hebb.txt.
%% See PLExp2/modelfits/Hebb_fits.txt, the entry of April 6, 2004.  

 Mparams=Sres_nofk36.opt_par    %%******  Adopted in PLM_PARAMS.M
Mparams = 
      rep_size: [7 5 1]
       max_act: 0.5000
      rep_gain: 0.8000
      out_gain: 5.1840
     rep_noise: 0.1000
     out_noise: 0.1534
      W_minmax: [-1 1]
        W_init: 0.1608
       W0_seed: [35x1 double]
    learn_rate: 0.001682
    runav_rate: 0.0200
     criterion: 0.9094
      fdbk_wgt: 0.5000
    fdbk_fract: 0
      blk_size: 300



***************************************************************************
****
****  24 June 2005  --  No-feedback fits to the feedback data set (PLExp1)
****

 clear all ; cd('C:\work\PLModel1'); load PLM_CACHE;
 load sched;load('C:\work\PLPaper2\simul\all_zP_data.mat');clear Idef mdprfk32 mdprnf36 mZfk32 mZnf36;
 global HUMAN_ZCONGR ; HUMAN_ZCONGR = eZfk32'; whos
  Name               Size         Bytes  Class
--------------------------------------------------------------
  HUMAN_ZCONGR       6x32          1536  double array (global)
  PLM_CACHE         12x1       16803792  struct array (global)
  bnd                1x6             48  double array
  eZfk32            32x6           1536  double array
  eZnf36            36x6           1728  double array
  edprfk32          32x3            768  double array
  edprnf36          36x3            864  double array
  sched1            32x1           9088  cell array
  sched2            32x1           9088  cell array
--------------------------------------------------------------

%% Prepare and pack stimuli and "chance events",  see MAKE_CHEV
N_trials=9600; N_runs=2*10;
for k=1:N_runs/2 d=block_from_cache(sched1,PLM_CACHE);Mdata(k).stim=cat(1,d{:});Mdata(k).chev=make_chev(N_trials);end;
for k=(N_runs/2+1):N_runs d=block_from_cache(sched2,PLM_CACHE);Mdata(k).stim=cat(1,d{:});Mdata(k).chev=make_chev(N_trials);end;
d=cat(3,Mdata(:).stim);d=squeeze(d(:,3,:));imagesc(d);clear d  % sanity check

 Mparams=PLM_params;Mparams.fdbk_fract=0     % newly updated, see above
Mparams = 
      rep_size: [7 5 1]
       max_act: 0.5000
      rep_gain: 0.8000
      out_gain: 5.2000
     rep_noise: 0.1000
     out_noise: 0.1530
      W_minmax: [-1 1]
        W_init: 0.1600
       W0_seed: [35x1 double]
    learn_rate: 0.00168
    runav_rate: 0.0200
     criterion: 1
      fdbk_wgt: 0.5000    % still irrelevant because the model still runs without feedback
    fdbk_fract: 0         % <-- sic!
      blk_size: 300


%%  Test-run to make sure the program runs
%
 md=Mdata(1);md.params=Mparams;[o,Wh]=PLM_Hebb2(md);foo=Wh(:,1:10:end);for k=1:5 subplot(2,3,k);plot(foo([1:7]+7*k-7,:)','b');axis([0 1090 -.5 +.5]);set(gca,'xtick',[0:120:1080],'xticklabel',[],'ytick',[-.5:.1:+.5]);grid on;end
 Z=PLM_Zcongr2(md);clf;plot_PLM_fit(Z);   % [6x32]
 PLM_sumsqfit2(Z)
ans = 22.3760      % rather poor fit: mZcongr is too high and mZincongr is too low.

 ssq=zeros(N_runs,1);for k=1:N_runs md=Mdata(k);md.params=Mparams;Z=PLM_Zcongr2(md);ssq(k)=PLM_sumsqfit2(Z);end;describe(ssq)
    Mean  Std.dev       Min     Q25  Median     Q75     Max
------------------------------------------------------------
  22.370    1.206     19.61   21.68   22.20   23.05   24.65

 Sparams=PLM_search_params;Sparams.params=Mparams,clear Mparams
 Sparams.p2v_templ'
ans = 
    'VAL = PARAMS.learn_rate *100 ;'
    'VAL = PARAMS.out_noise ;'
    'VAL = PARAMS.W_init ;'
    'VAL = PARAMS.out_gain /10 ;'
    'VAL = PARAMS.criterion ;'

 x0=params2vector(Sparams.params,Sparams.p2v_templ)
x0 = 0.1680    0.1530    0.1600    0.5200    1.0000

% Test-run on 1 stimulus set
 tic;md=Sparams;md.model_data=Mdata(1);ssq=PLM_paramsearch(x0,md);toc;ssq
ssq = 22.3760   % same as above     % elapsed_time = 2.6 sec

%%% Parameter search, 24 June 2005, 11:25 am
 tic;[Sres.opt_par,Sres.ssq,Sres.opt_X,Sres.det]=paramsearch(Mdata,Sparams);toc
% elapsed_time = 4 h 40 min on the Dell OptiPlex

 Sres_nofk32=Sres, clear Sres;
Sres_nofk32 = 
    opt_par: [1x1 struct]
        ssq: 9.5828
      opt_X: [0.1569 0.1567 0.1669 1.2208 2.1880]
        det: [1x1 struct]

%% The summed squared error is SSQ=9.5828=8*1.1979 for the PLExp1 data set.
%% For comparison, SSQ was 7.7384=8*0.9673 under PLM_Hebb1 with feedback.
%% Note that SSQ cannot be compared directly because they depend on the
%% particular stimulus sequences (and chance events) used in the search.

 load('C:\work\PLModel1\newsimul\Sres.mat');save('C:\work\PLModel1\newsimul\Sres.mat','Sres_nofk36','Sres_nofk32');

 Mparams=Sres_nofk32.opt_par
Mparams = 
      rep_size: [7 5 1]
       max_act: 0.5000
      rep_gain: 0.8000
      out_gain: 12.2078   % Very different from Mparams_nofk36.out_gain=5.2
     rep_noise: 0.1000
     out_noise: 0.1567    % The Psych Review paper used out_noise=.195
      W_minmax: [-1 1]
        W_init: 0.1669    % The Psych Review paper used W_init=.17
       W0_seed: [35x1 double]
    learn_rate: 0.001569  % The Psych Review paper used .001500
    runav_rate: 0.0200
     criterion: 2.1880    % Remarkably close to the value (2.2) used in the Psych Review paper
      fdbk_wgt: 0.5000
    fdbk_fract: 0
      blk_size: 300

%%  Sanity check: Plot a sample model run.
 md=Mdata(1);md.params=Mparams;[o,Wh]=PLM_Hebb2(md);foo=Wh(:,1:10:end);for k=1:5 subplot(2,3,k);plot(foo([1:7]+7*k-7,:)','b');axis([0 1090 -.5 +.5]);set(gca,'xtick',[0:120:1080],'xticklabel',[],'ytick',[-.5:.1:+.5]);grid on;end
 Z=PLM_Zcongr2(md);clf;plot_PLM_fit(Z);PLM_sumsqfit2(Z)
ans = 9.3853      % and Figure looks good :-)


***************************************************************************
****
****  24 June 2005  --  Feedback fits to the feedback data set (PLExp1)
****  Use the same sequences and chev's as for the no-feedback fits.
****

#### There is one more free parameter: fdbk_wgt
#### Uncomment the corresponding section in PLM_TEMPLATE
 Sparams_nofk=Sparams;clear Sparams     % save the no-feedback search params
 Sparams_fdbk=PLM_search_params;Sparams_fdbk.params=Sres_nofk32.opt_params;Sparams_fdbk.params.fdbk_fract=1
 Sparams_fdbk=PLM_search_params;Sparams_fdbk.params=Sres_nofk32.opt_par;Sparams_fdbk.params.fdbk_fract=1
Sparams_fdbk = 
    lsfun_name: 'PLM_paramsearch'
    sumsq_name: 'PLM_sumsqfit2'
    model_name: 'PLM_Zcongr2'
        params: [1x1 struct]
     p2v_templ: {1x6 cell}
     v2p_templ: {1x6 cell}
        bounds: [2x6 double]
         optns: [1x1 struct]
       verbose: 0

 Sparams_fdbk.params
      out_gain: 12.2078
     out_noise: 0.1567
        W_init: 0.1669
    learn_rate: 0.0016
     criterion: 2.1880
      fdbk_wgt: 0.5000
    fdbk_fract: 1

 Sparams_fdbk.p2v_templ'
    'VAL = PARAMS.learn_rate *100 ;'
    'VAL = PARAMS.out_noise ;'
    'VAL = PARAMS.W_init ;'
    'VAL = PARAMS.out_gain /10 ;'
    'VAL = PARAMS.criterion ;'
    'VAL = PARAMS.fdbk_wgt ;'

 Sparams_fdbk.bounds
    0.1000    0.1000    0.1000    0.1000    0.5000         0
    1.0000    0.3000    0.3000    2.0000    3.0000   20.0000

 x0=params2vector(Sparams_fdbk.params,Sparams_fdbk.p2v_templ)
x0 = [0.1569    0.1567    0.1669    1.2208    2.1880    0.5000]

% Test-run on 1 stimulus set
 md=Sparams_fdbk;md.model_data=Mdata(1);ssq=PLM_paramsearch(x0,md)
ssq = 19.2405

%%% Parameter search, 24 June 2005, 17:20
 tic;[Sres.opt_par,Sres.ssq,Sres.opt_X,Sres.det]=paramsearch(Mdata,Sparams_fdbk);toc
% elapsed_time = 2 h  % had to re-start the search because MaxFunEvals were exceeded

@@@ Local minimum(?)
        ssq: 11.1573
      opt_X: [0.1636 0.2538 0.2995 1.1794 2.9235 7.9362]

 Sparams_fdbk.params.out_gain=8;Sparams_fdbk.params.out_noise=.2;Sparams_fdbk.params.criterion=1;Sparams_fdbk.params.W_init=.17;Sparams_fdbk.params
      rep_gain: 0.8000
      out_gain: 8
     rep_noise: 0.1000
     out_noise: 0.2000
        W_init: 0.1700
    learn_rate: 0.0016
    runav_rate: 0.0200
     criterion: 1
      fdbk_wgt: 0.5000
    fdbk_fract: 1

 tic;[Sres.opt_par,Sres.ssq,Sres.opt_X,Sres.det]=paramsearch(Mdata,Sparams_fdbk);toc
% elapsed_time = 2 hours, Max number of FunEvals exceeded.

 Sres_fdbk32_par6=Sres,clear Sres
Sres_fdbk32_par6 = 

    opt_par: [1x1 struct]
        ssq: 7.9808
      opt_X: [0.1525 0.2004 0.1658 0.4703 2.4386 2.8272]
        det: [1x1 struct]

 load('C:\work\PLModel1\newsimul\Sres.mat');save('C:\work\PLModel1\newsimul\Sres.mat','Sres_nofk36','Sres_nofk32','Sres_fdbk32_par6');


***************************************************************************
****
****  25 June 2005  --  Feedback fits to the no-feedback data set (PLExp2)
****  Use the same sequences and chev's as for the no-feedback fits.
****

 load('C:\work\PLModel1\newsimul\PLE2_optim.mat');   % formerly  nofdbk36_optim.mat
 load PLM_CACHE

 Sparams_nofk36=Sparams; clear Sparams ; Sparams_fdbk36=Sparams ; Sparams_fdbk36=PLM_search_params
Sparams_fdbk36 = 
    lsfun_name: 'PLM_paramsearch'
    sumsq_name: 'PLM_sumsqfit2'
    model_name: 'PLM_Zcongr2'
        params: [1x1 struct]
     p2v_templ: {1x6 cell}
     v2p_templ: {1x6 cell}
        bounds: [2x6 double]
         optns: [1x1 struct]
       verbose: 0

 Sparams_fdbk36.params.out_gain=5;Sparams_fdbk36.params.out_noise=.2;Sparams_fdbk36.params.criterion=1;Sparams_fdbk36.params.W_init=.17;Sparams_fdbk36.params.fdbk_wgt=2;Sparams_fdbk36.params
      rep_gain: 0.8000
      out_gain: 5
     rep_noise: 0.1000
     out_noise: 0.2000
        W_init: 0.1700
    learn_rate: 0.0017
    runav_rate: 0.0200
     criterion: 1
      fdbk_wgt: 2
    fdbk_fract: 1

 Sparams_fdbk36.p2v_templ'
    'VAL = PARAMS.learn_rate *100 ;'
    'VAL = PARAMS.out_noise ;'
    'VAL = PARAMS.W_init ;'
    'VAL = PARAMS.out_gain /10 ;'
    'VAL = PARAMS.criterion ;'
    'VAL = PARAMS.fdbk_wgt ;'

 Sparams_fdbk36.bounds
    0.1000    0.1000    0.1000    0.1000    0.5000         0
    1.0000    0.3000    0.3000    2.0000    3.0000   20.0000

 x0=params2vector(Sparams_fdbk36.params,Sparams_fdbk36.p2v_templ)
x0 = [0.1680    0.2000    0.1700    0.5000    1.0000    2.0000]

 whos
  Name                 Size         Bytes  Class
-----------------------------------------------------------------
  HUMAN_ZCONGR         6x36          1728  double array (global)
  Idef                 1x1           3384  struct array
  Mdata                1x20      12099744  struct array
  N_runs               1x1              8  double array
  N_trials             1x1              8  double array
  PLM_CACHE           12x1       16803792  struct array (global)
  Sparams_fdbk36       1x1           9472  struct array
  Sparams_nofk36       1x1           9180  struct array
  bnd36                1x6             48  double array
  eZfk32              32x6           1536  double array
  eZnf36              36x6           1728  double array
  edprfk32            32x3            768  double array
  edprnf36            36x3            864  double array
  sched36_1           36x1          10224  cell array
  sched36_2           36x1          10224  cell array
  x0                   1x6             48  double array
-----------------------------------------------------------------

% Test-run on 1 stimulus set
 md=Sparams_fdbk36;md.model_data=Mdata(1);ssq=PLM_paramsearch(x0,md)
ssq = 9.9753

%%% Parameter search, 25 June 2005, 18:30
 tic;[Sres.opt_par,Sres.ssq,Sres.opt_X,Sres.det]=paramsearch(Mdata,Sparams_fdbk36);toc
% elapsed_time = 16 hours!

 Sres_fdbk36_par6=Sres,clear Sres
Sres_fdbk36_par6 = 
    opt_par: [1x1 struct]
        ssq: 8.5873
      opt_X: [0.1677 0.2116 0.1869 0.1092 0.8619 2.1322]
        det: [1x1 struct]


##############  Approximately optimal parameters so far  ####################
#                                                                           #
#Data Model Fdbk df | Sumsq   LrnRate Noise   Bias   Winit  OutGain  FbkWgt #
#-------------------+-------------------------------------------------------#
# 32   old  yes   4 |  7.74   .00150  .1950   2.200  .1700   - - -   - - -  #
# 32   2.0  yes   6 |  7.98   .00153  .2004   2.439  .1658   4.703   2.827  #
# 32   2.0   no   5 |  9.58   .00157  .1567   2.188  .1669  12.208   - - -  #
#-------------------+-------------------------------------------------------#
# 36   old   no   4 |  8.97   .0015*  .1580   0.870  .170*   - - -   - - -  #
# 36   2.0   no   5 |  8.78   .00168  .1534   0.909  .1608   5.184   - - -  #
# 36   2.0  yes   6 |  8.59   .00168  .2116   0.862  .1869   1.092   2.132  #
#-------------------+-------------------------------------------------------#
#Data Model Fdbk df | Sumsq   LrnRate Noise   Bias   Winit  OutGain  FbkWgt #
#                                                                           #
#############################################################################


***************************************************************************
****
****  26 June 2005  --  Fix  learn_rate=.0016, W_init=.17, out_gain=5
****  Run PARAMSEARCH again. New stimulus sequences to avoid overfitting.
****
****  No-feedback fits to the feedback data set (PLExp1)
****  Two free parameters:  out_noise and criterion
****


%%%%%  Modify PLM_PARAMS.M to include the new defaults:
% learn_rate = .0016   % it was .0015 in the Psych Review paper
% W_init = .17         % same as in the Psych Review paper
% out_gain = 5         % new parameter
%%%%%

 clear all ; cd('C:\work\PLModel1'); global PLM_CACHE; load PLM_CACHE;
 load sched;load('C:\work\PLPaper2\simul\all_zP_data.mat');clear Idef mdprfk32 mdprnf36 mZfk32 mZnf36;
 global HUMAN_ZCONGR ; HUMAN_ZCONGR = eZfk32';

%% Prepare and pack stimuli and "chance events",  see MAKE_CHEV
N_trials=9600; N_runs=2*10;
for k=1:N_runs/2 d=block_from_cache(sched1,PLM_CACHE);Mdata(k).stim=cat(1,d{:});Mdata(k).chev=make_chev(N_trials);end;
for k=(N_runs/2+1):N_runs d=block_from_cache(sched2,PLM_CACHE);Mdata(k).stim=cat(1,d{:});Mdata(k).chev=make_chev(N_trials);end;
d=cat(3,Mdata(:).stim);d=squeeze(d(:,3,:));imagesc(d);clear d  % sanity check

%%% Free params out_noise and criterion. Comment out the entries for all other params in PLM_TEMPLATE.
 Sparams_nofk=PLM_search_params;Sparams_nofk.params.fdbk_fract=0
Sparams_nofk = 
    lsfun_name: 'PLM_paramsearch'
    sumsq_name: 'PLM_sumsqfit2'
    model_name: 'PLM_Zcongr2'
        params: [1x1 struct]
     p2v_templ: {'VAL = PARAMS.out_noise ;'  'VAL = PARAMS.criterion ;'}
     v2p_templ: {'PARAMS.out_noise = VAL ;'  'PARAMS.criterion = VAL ;'}
        bounds: [2x2 double]
         optns: [1x1 struct]
       verbose: 0

 Sparams_nofk.bounds
ans = 0.1000    0.5000
      0.3000    3.0000

 Sparams_nofk.params
      rep_size: [7 5 1]
       max_act: 0.5000
      rep_gain: 0.8000
      out_gain: 5
     rep_noise: 0.1000
     out_noise: 0.1600
      W_minmax: [-1 1]
        W_init: 0.1700
       W0_seed: [35x1 double]
    learn_rate: 0.0016
    runav_rate: 0.0200
     criterion: 1
      fdbk_wgt: 1
    fdbk_fract: 0
      blk_size: 300

%%%%  No-feedback parameter search, 32-block data set, 26 June 2005, 14:14.
 tic;[Sres.opt_par,Sres.ssq,Sres.opt_X,Sres.det]=paramsearch(Mdata,Sparams_nofk);toc
% elapsed_time = 60 minutes on the Dell OptiPlex

 Sres
Sres = 
    opt_par: [1x1 struct]
        ssq: 20.9690             % <-- Unsatisfactory fit
      opt_X: [0.1815 1.0752]
        det: [1x1 struct]

%% Increase out_gain from 5 to 10 and try again:
 Sres_nofk32_g5=Sres;clear Sres;Sparams_nofk.params.out_gain=10;Sparams_nofk.params.out_noise=.18;Sparams_nofk.params
      rep_gain: 0.8000
      out_gain: 10        % <-- Sic!
     out_noise: 0.1800
        W_init: 0.1700
    learn_rate: 0.0016
     criterion: 1
      fdbk_wgt: 1
    fdbk_fract: 0

 tic;[Sres.opt_par,Sres.ssq,Sres.opt_X,Sres.det]=paramsearch(Mdata,Sparams_nofk);toc
% elapsed_time = 45 minutes on the Dell OptiPlex

 Sres_nofk32_g10=Sres,clear Sres;
Sres_nofk32_g10 = 
    opt_par: [1x1 struct]
        ssq: 9.9953
      opt_X: [0.1582 2.1392]
        det: [1x1 struct]

%% Re-fit the 5-gain condition, which looks stuck in a local minimum (criterion too low)
 Sparams_nofk.params=Sres_nofk32_g10.opt_par;Sparams_nofk.params.out_gain=5;Sparams_nofk.params
      rep_gain: 0.8000
      out_gain: 5
     rep_noise: 0.1000
     out_noise: 0.1582
        W_init: 0.1700
    learn_rate: 0.0016
    runav_rate: 0.0200
     criterion: 2.1392
      fdbk_wgt: 1
    fdbk_fract: 0

 tic;[Sres.opt_par,Sres.ssq,Sres.opt_X,Sres.det]=paramsearch(Mdata,Sparams_nofk);toc
% elapsed_time = 30 minutes on the Dell OptiPlex

 Sres_nofk32_g5=Sres;clear Sres;
Sres_nofk32_g5 = 
    opt_par: [1x1 struct]
        ssq: 10.5793
      opt_X: [0.1495 2.1446]
        det: [1x1 struct]

 load('C:\work\PLModel1\newsimul\Sres.mat');save('C:\work\PLModel1\newsimul\Sres.mat','Sres_nofk36_par5','Sres_nofk32_par5','Sres_nofk32_g05','Sres_nofk32_g10','Sres_fdbk32_par6','Sres_fdbk36_par6');


***************************************************************************
****
****  26 June 2005  --  Feedback fits to the feedback data set (PLExp1)
****
****  Recruit the IBM 8310 computer from cubicle B.
****  It has 2.5GHz processor and 768 MB RAM and runs WinXP
****  Matlab 6.5.1 R13 SP1  (The Dell OptiPlex runs Matlab 5.? ..)
****

######  FTP all utlities, PLModel1, PLExp1, PLExp2 files
>> global HUMAN_ZCONGR PLM_CACHE    % must be explicitly declared
>> load('C:\Users\APetrov\PLModel1\newsimul\PLE1_optim.mat');
>> load('C:\Users\APetrov\PLModel1\PLE_CACHE.mat');

>> Sparams_fdbk=PLM_search_params
Sparams_fdbk = 
    lsfun_name: 'PLM_paramsearch'
    sumsq_name: 'PLM_sumsqfit2'
    model_name: 'PLM_Zcongr2'
        params: [1x1 struct]
     p2v_templ: {1x3 cell}
     v2p_templ: {1x3 cell}
        bounds: [2x3 double]
         optns: [1x1 struct]
       verbose: 0

>> Sparams_fdbk.p2v_templ'
    'VAL = PARAMS.out_noise ;'
    'VAL = PARAMS.criterion ;'
    'VAL = PARAMS.fdbk_wgt ;'

>> Sparams_fdbk.bounds
    0.1000    0.5000         0
    0.3000    3.0000    5.0000

>> Sparams_fdbk.params
      rep_gain: 0.8000
      out_gain: 5
     rep_noise: 0.1000
     out_noise: 0.1600
        W_init: 0.1700
    learn_rate: 0.0016
    runav_rate: 0.0200
     criterion: 1
      fdbk_wgt: 1
    fdbk_fract: 1
      blk_size: 300

%%  Test-run to make sure everything still runs on the new platform
>> x0=params2vector(Sparams_fdbk.params,Sparams_fdbk.p2v_templ)
x0 = 0.1600    1.0000    1.0000

>> md=Sparams_fdbk;md.model_data=Mdata(1);ssq=PLM_paramsearch(x0,md)
ssq = 41.3834


>> HZ=PLM_Zcongr2(md) ; PLM_sumsqfit2(HZ)
ans = 41.3834


%%% Parameter search, 26 June 2005, 32-block data set, PLM_Hebb2 with feedback
 tic;[Sres.opt_par,Sres.ssq,Sres.opt_X,Sres.det]=paramsearch(Mdata,Sparams_fdbk);toc
% elapsed_time = 50 minutes on IBM 8310

>> Sres_fdbk32_g05=Sres,clear Sres
Sres_fdbk32_g05 = 
    opt_par: [1x1 struct]
        ssq: 7.9921
      opt_X: [0.2057 2.2098 3.5578]
        det: [1x1 struct]


%% Increase out_gain from 5 to 10 and try again:
>> Sparams_fdbk.params=Sres_fdbk32_gain5.opt_par;Sparams_fdbk.params.out_gain=10;Sparams_fdbk.params
      rep_gain: 0.8000
      out_gain: 10
     rep_noise: 0.1000
     out_noise: 0.2057
        W_init: 0.1700
    learn_rate: 0.0016
    runav_rate: 0.0200
     criterion: 2.2098
      fdbk_wgt: 3.5578
    fdbk_fract: 1
      blk_size: 300

>> tic;[Sres.opt_par,Sres.ssq,Sres.opt_X,Sres.det]=paramsearch(Mdata,Sparams_fdbk);toc
% elapsed_time = 55 minutes on IBM 8310

>> Sres_fdbk32_g10=Sres,clear Sres
Sres_fdbk32_g10 = 
    opt_par: [1x1 struct]
        ssq: 7.9466
      opt_X: [0.2061 2.0753 3.5578]
        det: [1x1 struct]


%%%%%%%%%  Duplicate the no-feedback fits, to cross-validate with the Dell (which runs an earlier Matlab version)
>> Sparams_nofk.params.out_noise=.18;Sparams_nofk.params.out_gain=10;Sparams_nofk.params
      rep_gain: 0.8000
      out_gain: 10
     rep_noise: 0.1000
     out_noise: 0.1800
        W_init: 0.1700
    learn_rate: 0.0016
    runav_rate: 0.0200
     criterion: 1
      fdbk_wgt: 1
    fdbk_fract: 0
      blk_size: 300


@@@@ Error: Reference to non-existent field 'MaxSQPIter'.
>> old_optns=Sparams_nofk.optns;o=optimset('fmincon');o.Display='iter';o.LargeScale='off';o.MaxFunEvals=old_optns.MaxFunEvals;
>> o.TolCon=old_optns.TolCon;o.TolFun=old_optns.TolFun;o.TolX=old_optns.TolX
>> Sparams_nofk.optns=o

>> tic;[Sres.opt_par,Sres.ssq,Sres.opt_X,Sres.det]=paramsearch(Mdata,Sparams_nofk);toc
% elapsed_time = ?? minutes on IBM 8310

>> Sres_nofk32_g10_alt=Sres,clear Sres
Sres_nofk32_g10_alt = 
    opt_par: [1x1 struct]
        ssq: 10.0547
      opt_X: [0.1593 2.1559]
        det: [1x1 struct]
 
%% The analogous search on the Dell yielded SSQ=9.99, out_noise=.1582, criterion=2.139. It cross-validates!
>> save('Sres_fdbk32.mat','Sres_fdbk32_gain05','Sres_fdbk32_gain10','Sres_nofk32_gain10_alt');

%% And after consolidation with the three Sres structures generated on the IBM
 whos
  Name                      Size         Bytes  Class
-------------------------------------------------------------
  Sres_fdbk32_g05           1x1           3332  struct array
  Sres_fdbk32_g10           1x1           3332  struct array
  Sres_fdbk32_par6          1x1           3356  struct array
  Sres_fdbk36_par6          1x1           3356  struct array
  Sres_nofk32_g05           1x1           3324  struct array
  Sres_nofk32_g10           1x1           3324  struct array
  Sres_nofk32_g10_alt       1x1           3324  struct array
  Sres_nofk32_par5          1x1           3348  struct array
  Sres_nofk36_par5          1x1           3348  struct array
-------------------------------------------------------------

 save('C:\work\PLModel1\newsimul\Sres.mat');



##############  Approximately optimal parameters so far  ####################
#                                                                           #
#Data Model Fdbk df | Sumsq   LrnRate Noise   Bias   Winit  OutGain  FbkWgt #
#-------------------+-------------------------------------------------------#
# 32   old  yes   4 |  7.74   .00150  .1950   2.200  .1700   - - -   - - -  #
# 32   2.0  yes   6 |  7.98   .00153  .2004   2.439  .1658   4.703   2.827  #
# 32   2.0  yes   3 |  7.99   .0016*  .2057   2.201  .170*   5.0**   3.558  #
# 32   2.0  yes   3 |  7.95   .0016*  .2061   2.075  .170*  10.0**   3.558  #
# 32   2.0   no   5 |  9.58   .00157  .1567   2.188  .1669  12.208   - - -  #
# 32   2.0   no   2 | 10.05   .0016*  .1593   2.145  .170*   5.0**   - - -  #
# 32   2.0   no   2 |  9.99   .0016*  .1582   2.139  .170*  10.0**   - - -  #  % Run1: Dell
# 32   2.0   no   2 | 10.05   .0016*  .1593   2.156  .170*  10.0**   - - -  #  % Run2: IBM
#-------------------+-------------------------------------------------------#
# 36   old   no   4 |  8.97   .0015*  .1580   0.870  .170*   - - -   - - -  #
# 36   2.0   no   5 |  8.78   .00168  .1534   0.909  .1608   5.184   - - -  #
# 36   2.0  yes   6 |  8.59   .00168  .2116   0.862  .1869   1.092   2.132  #
#-------------------+-------------------------------------------------------#
#Data Model Fdbk df | Sumsq   LrnRate Noise   Bias   Winit  OutGain  FbkWgt #
#                                                                           #
#############################################################################


####################
#####
#####  CONCLUSION:  Increasing the output gain from 5 to 10 seems
#####               to make no difference.  Commit out_gain=5.
#####
####################


***************************************************************************
****
****  26 June 2005  --  Feedback fits to the feedback data set (PLExp1)
****                    Constrain  fdbk_wgt to a low value (=1=max_weight)
****

 Sparams_fdbk=PLM_search_params
Sparams_fdbk = 
    lsfun_name: 'PLM_paramsearch'
    sumsq_name: 'PLM_sumsqfit2'
    model_name: 'PLM_Zcongr2'
        params: [1x1 struct]
     p2v_templ: {'VAL = PARAMS.out_noise ;'  'VAL = PARAMS.criterion ;'}
     v2p_templ: {'PARAMS.out_noise = VAL ;'  'PARAMS.criterion = VAL ;'}
        bounds: [2x2 double]
         optns: [1x1 struct]
       verbose: 0

 Sparams_fdbk.params.fdbk_wgt=1;   % <-- Sic!

 Sparams_fdbk.params.out_noise=.18;Sparams_fdbk.params.criterion=2; % Initial approx
 Sparams_fdbk.params
      rep_size: [7 5 1]
       max_act: 0.5000
      rep_gain: 0.8000
      out_gain: 5
     rep_noise: 0.1000
     out_noise: 0.1800
      W_minmax: [-1 1]
        W_init: 0.1700
       W0_seed: [35x1 double]
    learn_rate: 0.0016
    runav_rate: 0.0200
     criterion: 2
      fdbk_wgt: 1
    fdbk_fract: 1
      blk_size: 300

 tic;[Sres.opt_par,Sres.ssq,Sres.opt_X,Sres.det]=paramsearch(Mdata,Sparams_fdbk);toc
% elapsed_time = 50 minutes on Dell OptiPlex

 Sres_fdbk32_Wf10=Sres,clear Sres
Sres_fdbk32_Wf10 = 
    opt_par: [1x1 struct]
        ssq: 8.1474
      opt_X: [0.2100 2.2474]
        det: [1x1 struct]


**********  Now try the complement: fix out_noise=.18 and allow fdbk_wgt to vary
***
%%% Uncomment the relevant entry in PLM_template
 Sparams_fdbk=PLM_search_params

 Sparams_fdbk1=PLM_search_params
Sparams_fdbk1 = 
    lsfun_name: 'PLM_paramsearch'
    sumsq_name: 'PLM_sumsqfit2'
    model_name: 'PLM_Zcongr2'
        params: [1x1 struct]
     p2v_templ: {'VAL = PARAMS.criterion ;'  'VAL = PARAMS.fdbk_wgt ;'}
     v2p_templ: {'PARAMS.criterion = VAL ;'  'PARAMS.fdbk_wgt = VAL ;'}
        bounds: [2x2 double]
         optns: [1x1 struct]
       verbose: 0

 Sparams_fdbk1.params=Sres_fdbk32_Wf10.opt_par;Sparams_fdbk1.params.out_noise=.18;
 Sparams_fdbk1.params
      rep_gain: 0.8000
      out_gain: 5
     rep_noise: 0.1000
     out_noise: 0.1800
        W_init: 0.1700
    learn_rate: 0.0016
    runav_rate: 0.0200
     criterion: 2.2474
      fdbk_wgt: 1
    fdbk_fract: 1
      blk_size: 300

 tic;[Sres.opt_par,Sres.ssq,Sres.opt_X,Sres.det]=paramsearch(Mdata,Sparams_fdbk1);toc
% elapsed_time = 70 minutes on Dell OptiPlex

 Sres_fdbk32_oN18=Sres,clear Sres
Sres_fdbk32_oN18 = 
    opt_par: [1x1 struct]
        ssq: 8.9294
      opt_X: [2.2071 0.1561]
        det: [1x1 struct]


********  Try also  out_noise=[.16 .17 .19 .20]
*
Sparams_fdbk1.params.out_noise=.16;
tic;[Sres.opt_par,Sres.ssq,Sres.opt_X,Sres.det]=paramsearch(Mdata,Sparams_fdbk1);toc
Sres_fdbk32_oN16=Sres,clear Sres;save foo

Sres_fdbk32_oN16 = 
    opt_par: [1x1 struct]
        ssq: 9.8328
      opt_X: [2.2262 0.0477]
        det: [1x1 struct]


Sparams_fdbk1.params.out_noise=.17;
tic;[Sres.opt_par,Sres.ssq,Sres.opt_X,Sres.det]=paramsearch(Mdata,Sparams_fdbk1);toc
Sres_fdbk32_oN17=Sres,clear Sres;save foo

Sres_fdbk32_oN17 = 
    opt_par: [1x1 struct]
        ssq: 9.3135
      opt_X: [2.2075 0.0917]
        det: [1x1 struct]


Sparams_fdbk1.params.out_noise=.19;
tic;[Sres.opt_par,Sres.ssq,Sres.opt_X,Sres.det]=paramsearch(Mdata,Sparams_fdbk1);toc
Sres_fdbk32_oN19=Sres,clear Sres;save foo

Sres_fdbk32_oN19 = 
    opt_par: [1x1 struct]
        ssq: 8.5922
      opt_X: [2.2974 0.2613]
        det: [1x1 struct]


Sparams_fdbk1.params.out_noise=.20;
tic;[Sres.opt_par,Sres.ssq,Sres.opt_X,Sres.det]=paramsearch(Mdata,Sparams_fdbk1);toc
Sres_fdbk32_oN20=Sres,clear Sres;save foo

Sres_fdbk32_oN20 = 
    opt_par: [1x1 struct]
        ssq: 8.0369
      opt_X: [2.2554 0.9548]
        det: [1x1 struct]


##############  Approximately optimal parameters so far  #################### 2005-06-27
#                                                                           #
#Data Model Fdbk df | Sumsq   LrnRate Noise   Bias   Winit  OutGain  FbkWgt # Sres_struct
#-------------------+-------------------------------------------------------# -----------
# 32   old  yes   4 |  7.74   .00150  .1950   2.200  .1700   - - -   - - -  #
# 32   2.0  yes   6 |  7.98   .00153  .2004   2.439  .1658   4.703   2.827  # fdbk32_par6
# 32   2.0  yes   3 |  7.99   .0016*  .2057   2.201  .170*   5.0**   3.558  # fdbk32_g05
# 32   2.0  yes   3 |  7.95   .0016*  .2061   2.075  .170*  10.0**   3.558  # fdbk32_g10
# 32   2.0  yes   2 |  9.83   .0016*  .16**   2.226  .170*   5.0**   0.048  # fdbk32_oN16
# 32   2.0  yes   2 |  9.31   .0016*  .17**   2.208  .170*   5.0**   0.092  # fdbk32_oN17
# 32   2.0  yes   2 |  8.93   .0016*  .18**   2.207  .170*   5.0**   0.156  # fdbk32_oN18
# 32   2.0  yes   2 |  8.59   .0016*  .19**   2.297  .170*   5.0**   0.261  # fdbk32_oN19
# 32   2.0  yes   2 |  8.04   .0016*  .20**   2.255  .170*   5.0**   0.955  # fdbk32_oN20
# 32   2.0  yes   2 |  8.15   .0016*  .2100   2.247  .170*   5.0**   1.00*  # fdbk32_Wf10
#                   |                                                       #
# 32   2.0   no   5 |  9.58   .00157  .1567   2.188  .1669  12.208   - - -  # nofk32_par5
# 32   2.0   no   2 | 10.58   .0016*  .1495   2.145  .170*   5.0**   - - -  # nofk32_g05
# 32   2.0   no   2 |  9.99   .0016*  .1582   2.139  .170*  10.0**   - - -  # nofk32_g10     % Run1: Dell
# 32   2.0   no   2 | 10.05   .0016*  .1593   2.156  .170*  10.0**   - - -  # nofk32_g10_alt % Run2: IBM
#-------------------+-------------------------------------------------------#
# 36   old   no   4 |  8.97   .0015*  .1580   0.870  .170*   - - -   - - -  #
# 36   2.0   no   5 |  8.78   .00168  .1534   0.909  .1608   5.184   - - -  # nofk36_par5
# 36   2.0  yes   6 |  8.59   .00168  .2116   0.862  .1869   1.092   2.132  # fdbk36_par6
#-------------------+-------------------------------------------------------# -----------
#Data Model Fdbk df | Sumsq   LrnRate Noise   Bias   Winit  OutGain  FbkWgt # Sres_struct
#                                                                           #
#############################################################################


***************************************************************************
****
****  27 June 2005  --  Build up the 36-block portion of the table (PLExp2 protocol)
****

clear all; global HUMAN_ZCONGR PLM_CACHE
load(fullfile(PLM_pathstr,'PLM_CACHE.mat'));clear Idef
load(fullfile(PLM_pathstr,'newsimul','PLE2_optim.mat'));
load(fullfile(PLM_pathstr,'newsimul','Sres.mat'));

********  No-feedback runs, PLExp2 data
%%% Fixed parameters: learn_rate=.0016, W_init=.17
%%% Free parameters:  out_noise, criterion, out_gain
%%% (Un)comment sections in PLM_TEMPLATE.M accordingly
 Sparams_nofk36=PLM_search_params
Sparams_nofk36 = 
    lsfun_name: 'PLM_paramsearch'
    sumsq_name: 'PLM_sumsqfit2'
    model_name: 'PLM_Zcongr2'
        params: [1x1 struct]
     p2v_templ: {1x3 cell}
     v2p_templ: {1x3 cell}
        bounds: [2x3 double]
         optns: [1x1 struct]
       verbose: 0

 Sparams_nofk36.p2v_templ'
    'VAL = PARAMS.out_noise ;'
    'VAL = PARAMS.out_gain /10 ;'
    'VAL = PARAMS.criterion ;'

 Sparams_nofk36.params.fdbk_fract=0;Sparams_nofk36.params
      rep_gain: 0.8000
      out_gain: 5
     rep_noise: 0.1000
     out_noise: 0.1600
        W_init: 0.1700
    learn_rate: 0.0016
    runav_rate: 0.0200
     criterion: 1
      fdbk_wgt: 1
    fdbk_fract: 0
      blk_size: 300

 tic;[Sres.opt_par,Sres.ssq,Sres.opt_X,Sres.det]=paramsearch(Mdata,Sparams_nofk36);toc
 Sres_nofk36_par3=Sres,clear Sres
Sres_nofk36_par3 = 
    opt_par: [1x1 struct]
        ssq: 8.6631
      opt_X: [0.1527 0.4495 0.9234]
        det: [1x1 struct]


%%%%%%  Fix out_gain=5.0 and re-run.
% Uncomment the out_gain section in PLM_TEMPLATE and...
 Sparams_nofk36=PLM_search_params
Sparams_nofk36 = 
    lsfun_name: 'PLM_paramsearch'
    sumsq_name: 'PLM_sumsqfit2'
    model_name: 'PLM_Zcongr2'
        params: [1x1 struct]
     p2v_templ: {'VAL = PARAMS.out_noise ;'  'VAL = PARAMS.criterion ;'}
     v2p_templ: {'PARAMS.out_noise = VAL ;'  'PARAMS.criterion = VAL ;'}
        bounds: [2x2 double]
         optns: [1x1 struct]
       verbose: 0

 Sparams_nofk36.params=Sres_nofk36_par3.opt_par;Sparams_nofk36.params.out_gain=5;Sparams_nofk36.params
      rep_gain: 0.8000
      out_gain: 5
     rep_noise: 0.1000
     out_noise: 0.1527
      W_minmax: [-1 1]
        W_init: 0.1700
       W0_seed: [35x1 double]
    learn_rate: 0.0016
    runav_rate: 0.0200
     criterion: 0.9234
      fdbk_wgt: 1
    fdbk_fract: 0
      blk_size: 300

 tic;[Sres.opt_par,Sres.ssq,Sres.opt_X,Sres.det]=paramsearch(Mdata,Sparams_nofk36);toc;
 Sres_nofk36_g05=Sres,clear Sres
Sres_nofk36_g05 = 
    opt_par: [1x1 struct]
        ssq: 8.6330
      opt_X: [0.1558 0.9514]
        det: [1x1 struct]


%%%%%%  Fix out_gain=10.0 and re-run.
 Sparams_nofk36.params=Sres_nofk36_g05.opt_par;Sparams_nofk36.params.out_gain=10;Sparams_nofk36.params
 tic;[Sres.opt_par,Sres.ssq,Sres.opt_X,Sres.det]=paramsearch(Mdata,Sparams_nofk36);toc;
 Sres_nofk36_g10=Sres,clear Sres
Sres_nofk36_g10 = 
    opt_par: [1x1 struct]
        ssq: 9.6451
      opt_X: [0.1653 1.0773]
        det: [1x1 struct]



********  Feedback runs, PLExp2 data
%%% Fixed parameters: learn_rate=.0016, W_init=.17
%%% Free parameters:  out_noise, criterion, out_gain, fdbk_wgt
%%% (Un)comment sections in PLM_TEMPLATE.M accordingly
 Sparams_fdbk36=PLM_search_params
Sparams_fdbk36 = 
    lsfun_name: 'PLM_paramsearch'
    sumsq_name: 'PLM_sumsqfit2'
    model_name: 'PLM_Zcongr2'
        params: [1x1 struct]
     p2v_templ: {1x4 cell}
     v2p_templ: {1x4 cell}
        bounds: [2x4 double]
         optns: [1x1 struct]
       verbose: 0

 Sparams_fdbk36.p2v_templ'
    'VAL = PARAMS.out_noise ;'
    'VAL = PARAMS.out_gain /10 ;'
    'VAL = PARAMS.criterion ;'
    'VAL = PARAMS.fdbk_wgt ;'

 Sparams_fdbk36.params.out_noise=.21;Sparams_fdbk36.params.fdbk_wgt=2;Sparams_fdbk36.params
      rep_gain: 0.8000
      out_gain: 5
     rep_noise: 0.1000
     out_noise: 0.2100
        W_init: 0.1700
    learn_rate: 0.0016
    runav_rate: 0.0200
     criterion: 1
      fdbk_wgt: 2
    fdbk_fract: 1
      blk_size: 300

 tic;[Sres.opt_par,Sres.ssq,Sres.opt_X,Sres.det]=paramsearch(Mdata,Sparams_fdbk36);toc
 Sres_fdbk36_par4=Sres,clear Sres
Sres_fdbk36_par4 = 
    opt_par: [1x1 struct]
        ssq: 8.7471
      opt_X: [0.2033 0.4680 0.8316 1.9922]
        det: [1x1 struct]

%%%%%%  Fix out_noise=.16, out_gain=5 and re-run.
% Comment out the corresponding fields in PLM_TEMPLATE.M
 Sparams_fdbk36=PLM_search_params
    lsfun_name: 'PLM_paramsearch'
    sumsq_name: 'PLM_sumsqfit2'
    model_name: 'PLM_Zcongr2'
        params: [1x1 struct]
     p2v_templ: {'VAL = PARAMS.criterion ;'  'VAL = PARAMS.fdbk_wgt ;'}
     v2p_templ: {'PARAMS.criterion = VAL ;'  'PARAMS.fdbk_wgt = VAL ;'}
        bounds: [2x2 double]
         optns: [1x1 struct]
       verbose: 0

 Sparams_fdbk36.params=Sres_fdbk36_par4.opt_par;Sparams_fdbk36.params.out_gain=5;Sparams_fdbk36.params.out_noise=.16;
 Sparams_fdbk36.params.fdbk_wgt=0.03;Sparams_fdbk36.params.criterion=1;Sparams_fdbk36.params    % initial approx
      rep_gain: 0.8000
      out_gain: 5
     rep_noise: 0.1000
     out_noise: 0.1600
      W_minmax: [-1 1]
        W_init: 0.1700
       W0_seed: [35x1 double]
    learn_rate: 0.0016
    runav_rate: 0.0200
     criterion: 1
      fdbk_wgt: 0.0300
    fdbk_fract: 1

 tic;[Sres.opt_par,Sres.ssq,Sres.opt_X,Sres.det]=paramsearch(Mdata,Sparams_fdbk36);toc;
 Sres_fdbk36_oN16=Sres,clear Sres
Sres_fdbk36_oN16 = 
    opt_par: [1x1 struct]
        ssq: 8.3918
      opt_X: [0.9359 0.0193]
        det: [1x1 struct]


%%%%%%  Experiment with out_noise=[.17 .18 .19 .20]
 tic;Sparams_fdbk36.params.out_noise=.17;[Sres.opt_par,Sres.ssq,Sres.opt_X,Sres.det]=paramsearch(Mdata,Sparams_fdbk36);toc
 Sres_fdbk36_oN17=Sres,clear Sres
Sres_fdbk36_oN17 = 
    opt_par: [1x1 struct]
        ssq: 8.2934
      opt_X: [0.9431 0.0471]
        det: [1x1 struct]


 tic;Sparams_fdbk36.params.out_noise=.18;[Sres.opt_par,Sres.ssq,Sres.opt_X,Sres.det]=paramsearch(Mdata,Sparams_fdbk36);toc
 Sres_fdbk36_oN18=Sres,clear Sres
Sres_fdbk36_oN18 = 
    opt_par: [1x1 struct]
        ssq: 8.1987
      opt_X: [0.9596 0.1018]
        det: [1x1 struct]


 tic;Sparams_fdbk36.params.out_noise=.19;[Sres.opt_par,Sres.ssq,Sres.opt_X,Sres.det]=paramsearch(Mdata,Sparams_fdbk36);toc
 Sres_fdbk36_oN19=Sres,clear Sres
Sres_fdbk36_oN19 = 
    opt_par: [1x1 struct]
        ssq: 8.2155
      opt_X: [0.9307 0.1908]
        det: [1x1 struct]


 tic;Sparams_fdbk36.params.out_noise=.20;[Sres.opt_par,Sres.ssq,Sres.opt_X,Sres.det]=paramsearch(Mdata,Sparams_fdbk36);toc
 Sres_fdbk36_oN20=Sres,clear Sres
Sres_fdbk36_oN20 = 
    opt_par: [1x1 struct]
        ssq: 8.4998
      opt_X: [0.9140 0.2219]
        det: [1x1 struct]

 save(fullfile(PLM_pathstr,'newsimul','Sres_v20.mat'));



##############  Approximately optimal parameters so far  #################### 2005-06-27
#                                                                           #
#Data Model Fdbk df | Sumsq   LrnRate Noise   Bias   Winit  OutGain  FbkWgt # Sres_struct
#-------------------+-------------------------------------------------------# -----------
# 32   old  yes   4 |  7.74   .00150  .1950   2.200  .1700   - - -   - - -  # PLPaper1
# 32   2.0  yes   6 |  7.98   .00153  .2004   2.439  .1658   4.703   2.827  # fdbk32_par6
# 32   2.0  yes   3 |  7.99   .0016*  .2057   2.201  .170*   5.0**   3.558  # fdbk32_g05
# 32   2.0  yes   3 |  7.95   .0016*  .2061   2.075  .170*  10.0**   3.558  # fdbk32_g10
# 32   2.0  yes   2 |  9.83   .0016*  .16**   2.226  .170*   5.0**   0.048  # fdbk32_oN16
# 32   2.0  yes   2 |  9.31   .0016*  .17**   2.208  .170*   5.0**   0.092  # fdbk32_oN17
# 32   2.0  yes   2 |  8.93   .0016*  .18**   2.207  .170*   5.0**   0.156  # fdbk32_oN18
# 32   2.0  yes   2 |  8.59   .0016*  .19**   2.297  .170*   5.0**   0.261  # fdbk32_oN19
# 32   2.0  yes   2 |  8.04   .0016*  .20**   2.255  .170*   5.0**   0.955  # fdbk32_oN20
# 32   2.0  yes   2 |  8.15   .0016*  .2100   2.247  .170*   5.0**   1.00*  # fdbk32_Wf10
#                   |                                                       #
# 32   2.0   no   5 |  9.58   .00157  .1567   2.188  .1669  12.208   - - -  # nofk32_par5
# 32   2.0   no   2 | 10.58   .0016*  .1495   2.145  .170*   5.0**   - - -  # nofk32_g05
# 32   2.0   no   2 |  9.99   .0016*  .1582   2.139  .170*  10.0**   - - -  # nofk32_g10     % Run1: Dell
# 32   2.0   no   2 | 10.05   .0016*  .1593   2.156  .170*  10.0**   - - -  # nofk32_g10_alt % Run2: IBM
#-------------------+-------------------------------------------------------#------------
# 36   old   no   4 |  8.97   .0015*  .1580   0.870  .170*   - - -   - - -  # PLPaper2
# 36   2.0   no   5 |  8.78   .00168  .1534   0.909  .1608   5.184   - - -  # nofk36_par5
# 36   2.0   no   3 |  8.66   .0016*  .1527   0.923  .170*   4.495   - - -  # nofk36_par3
# 36   2.0   no   3 |  8.63   .0016*  .1558   0.951  .170*   5.0**   - - -  # nofk36_g05
# 36   2.0   no   3 |  9.64   .0016*  .1653   1.077  .170*  10.0**   - - -  # nofk36_g10
#                   |                                                       #
# 36   2.0  yes   6 |  8.59   .00168  .2116   0.862  .1869   1.092   2.132  # fdbk36_par6
# 36   2.0  yes   4 |  8.75   .0016*  .2033   0.832  .170*   6.680   1.992  # fdbk36_par4
# 36   2.0  yes   2 |  8.39   .0016*  .16**   0.934  .170*   5.0**   0.019  # fdbk36_oN16
# 36   2.0  yes   2 |  8.29   .0016*  .17**   0.943  .170*   5.0**   0.047  # fdbk36_oN17
# 36   2.0  yes   2 |  8.20   .0016*  .18**   0.960  .170*   5.0**   0.102  # fdbk36_oN18
# 36   2.0  yes   2 |  8.22   .0016*  .19**   0.931  .170*   5.0**   0.191  # fdbk36_oN19
# 36   2.0  yes   2 |  8.50   .0016*  .20**   0.914  .170*   5.0**   0.222  # fdbk36_oN20
#-------------------+-------------------------------------------------------# -----------
#Data Model Fdbk df | Sumsq   LrnRate Noise   Bias   Winit  OutGain  FbkWgt # Sres_struct
#                                                                           #
#############################################################################


%%%%  2005-06-28:  Introduce different 'feedback modes' in PLM_Hebb2, version 2.1.
%%%%  Simulations continue in Hebb2m_fits.txt
